<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('部门领导审批')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="col-sm-8">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-outside-add">
        <div class="form-group">
            <label class="col-sm-2 control-label">姓名：</label>
            <div class="col-sm-2">
                <input name="sysUserName" class="form-control" type="text" th:value="${outside.sysUserName}" readonly>
                <input style="display: none" name="id" class="form-control" type="text" th:value="${outside.id}" readonly>
            </div>
            <label class="col-sm-2 control-label">部门：</label>
            <div class="col-sm-2">
                <input name="sysUserName" class="form-control" type="text" th:value="${outside.sysDeptName}" readonly>
            </div>
            <label class="col-sm-2 control-label">岗位：</label>
            <div class="col-sm-2">
                <input name="job" class="form-control" type="text" th:value="${outside.job}" readonly>
            </div>
            <input name="sysUserid" style="display: none" class="form-control" type="text" th:value="${outside.sysUserid}" readonly>
            <input name="sysDeptid" style="display: none" class="form-control" type="text" th:value="${outside.sysDeptid}" readonly>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否有工作计划：</label>
            <div class="col-sm-3">
                <label class="radio-box">
                    <input type="radio" checked="checked" id="optionsRadios1" name="planeFlag" th:value="${outside.planeFlag}">
                    <span th:text="${outside.planeFlagString}"></span>
                </label>
            </div>
            <label class="col-sm-3 control-label">是否通过审批：</label>
            <div class="col-sm-3">
                <label class="radio-box">
                    <input type="radio" checked="checked" id="optionsRadios3" name="agreeFlag" th:value="${outside.agreeFlag}">
                    <span th:text="${outside.agreeFlagString}"></span>
                </label>

            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">预计出发时间：</label>
            <div class="col-sm-3">
                <div class="input-group date">
                    <input name="departureTime" class="form-control" placeholder="yyyy-MM-dd " type="text"  th:value="${#dates.format(outside.departureTime,'yyyy-MM-dd')}" readonly>
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>

            <label class="col-sm-3 control-label">预计返回时间：</label>
            <div class="col-sm-3">
                <div class="input-group date">
                    <input name="returnTime" class="form-control" placeholder="yyyy-MM-dd " type="text" th:value="${#dates.format(outside.returnTime,'yyyy-MM-dd')}" readonly>
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">出差性质：</label>
            <div class="col-sm-8">
                <input name="evectionType" class="form-control"  th:value="${outside.evectionType}" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">出发地：</label>
            <div class="col-sm-3">
                <input type="text" name="departurePlace" class="form-control"  th:value="${outside.departurePlace}" readonly></input>
            </div>
            <label class="col-sm-3 control-label">&nbsp;目的地：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
            <div class="col-sm-3">
                <input type="text" name="destinationPlace" class="form-control"  th:value="${outside.destinationPlace}" readonly></input>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">出差计划：</label>
            <div class="col-sm-8">
                <textarea type="text" name="evectionProject" class="form-control" th:text="${outside.evectionProject}" readonly></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">出差目的：</label>
            <div class="col-sm-8">
                <textarea type="text" name="evectionTarget" class="form-control"  th:text="${outside.evectionTarget}" readonly></textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">交通工具：</label>
            <div class="col-sm-8">
                <input type="text" name="transportation" class="form-control"  th:value="${outside.transportation}" readonly></input>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">同行人员：</label>
            <div class="col-sm-8">
                <input type="text" name="togetherMan" class="form-control"  th:value="${outside.togetherMan}" readonly></input>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">申请人：</label>
            <div class="col-sm-8">
                <input name="fromMan" class="form-control" type="text" th:value="${outside.fromMan}" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-3 control-label">总经理审批：</label>
            <div class="col-xs-8">
                <select class="form-control" id="hr" name="finance">
                    <option th:each="ul:${userlist}" th:value="${ul.loginName}" th:text="${ul.userName}" th:disabled="${ul.status == '1'}"></option>
                </select>
            </div>
        </div>
        <div class="form-group" style="display: none">
            <label class="col-sm-3 control-label">审批结果：</label>
            <div class="col-sm-8">
                <label class="radio-box">
                    <input type="text" id="secondLeader_input" name="secondLeader">同意</label>
        </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">审批意见：</label>
            <div class="col-sm-8">
                <textarea rows="5" name="comment" class="form-control" required></textarea>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-6 col-sm-offset-3">
                <input type="hidden"  name="taskid" id="taskid" th:value="${taskid}">
                <button class="btn btn-primary" onclick="submitHandler()" type="button"><i class="fa fa-check"></i>&nbsp;提交</button>
                <button style="display: none" class="btn btn-danger" onclick="forceEnd()" type="button"><i class="fa fa-close"></i>&nbsp;撤销</button>
                <button class="btn btn-warning" onclick="rebut()" type="button"><i class="fa fa-reply"></i>&nbsp;驳回</button>
            </div>
        </div>
    </form>
</div>
</div>
<div id="ibox-content" class="col-sm-4">
    <div id="vertical-timeline" class="vertical-container dark-timeline">
    </div>
</div>
</body>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefixupdate = ctx + "outside"
    var prefix = ctx + "task/manage"
    $("#form-outside-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        document.getElementById("secondLeader_input").value='true';

        $.operate.save(  prefixupdate+"/edit", $('#form-outside-add').serialize());
        var taskid = $("#taskid").val();
        var check = document.querySelector("input[name='secondLeader']").value;
        var comment = $("textarea[name=comment]").val();
        var json = {"secondLeader": check, "manage": $("#hr").val(), "comment": comment};
        $.ajax({
            url : prefix + "/completeTask/" + taskid,
            type : "POST",
            data : JSON.stringify(json), //转JSON字符串
            dataType: 'json',
            contentType:'application/json;charset=UTF-8', //contentType很重要
            success : function(result) {
                $.modal.msg("办理成功");
                const parent = window.parent;
                // 我的待办
                const myToDoIframe = parent.document.querySelector("iframe[src='/task/manage/mytask']");
                // 我的全部待办
                const myAllToDoIframe = parent.document.querySelector("iframe[src='/task/manage/alltasks']");
                myToDoIframe && myToDoIframe.contentWindow.location.reload(true);
                myAllToDoIframe && myAllToDoIframe.contentWindow.location.reload(true);
                $.modal.closeTab();
            }
        });
    }

    function forceEnd() {
        var taskid = $("#taskid").val();
        $.get("/dynamic/flow/forceEnd/" + taskid, function() {
            $.modal.msg("办理成功");
            const parent = window.parent;
            // 我的待办
            const myToDoIframe = parent.document.querySelector("iframe[src='/task/manage/mytask']");
            // 我的全部待办
            const myAllToDoIframe = parent.document.querySelector("iframe[src='/task/manage/alltasks']");
            myToDoIframe && myToDoIframe.contentWindow.location.reload(true);
            myAllToDoIframe && myAllToDoIframe.contentWindow.location.reload(true);
            $.modal.closeTab();
        });
    }

    function rebut() {
        document.getElementById("secondLeader_input").value='false';
        $.operate.save(  prefixupdate+"/edit", $('#form-outside-add').serialize());
        var taskid = $("#taskid").val();
        $.get("/dynamic/flow/jump/" + taskid + "/outside1", function() {
            $.modal.msg("办理成功");
            const parent = window.parent;
            // 我的待办
            const myToDoIframe = parent.document.querySelector("iframe[src='/task/manage/mytask']");
            // 我的全部待办
            const myAllToDoIframe = parent.document.querySelector("iframe[src='/task/manage/alltasks']");
            myToDoIframe && myToDoIframe.contentWindow.location.reload(true);
            myAllToDoIframe && myAllToDoIframe.contentWindow.location.reload(true);
            $.modal.closeTab();
        });
    }

    $(document).ready(function(){
        // 获取时间轴
        $.get(prefix + "/history/" + $("#taskid").val(), function(data){
            for (var a = 0; a < data.length ; a++) {
                $("#vertical-timeline").append("<div class=\"vertical-timeline-block\"><div class=\"vertical-timeline-icon lazur-bg\">" +
                    "<i class=\"fa fa-briefcase\"></i></div>" +
                    "<div class=\"vertical-timeline-content\">" +
                    "<span class=\"vertical-date\">开始 <small>" + data[a].startTime + "</small></span><br>" +
                    "<h2><b>" + data[a].assignee + ":</b>" + data[a].taskName + "</h2>" +
                    "<p>" + (data[a].comment || "-") + "</p>" +
                    "<span class=\"vertical-date\">结束 <small>" + (data[a].endTime || "-") + "</small></span>" +
                    "</div>" +
                    "</div>");
            }
        });
    });
</script>
</body>
</html>